#pragma once
#include <cstdint>
#include <memory>
#include "XnccType.h"
namespace xncc {
namespace foundation {
    class Timer
    {
      public:
        using s_ptr = std::shared_ptr<Timer>;
        // 精度 100 微妙
        static constexpr int resolve_precision = 100;

        Timer(types::Task tsk, int64_t when, int64_t interval);

        [[nodiscard]] int64_t getExpir() const { return expiration_; }
        types::timer_id_t     ID() const { return seqNo_; }
        void                  restart(int64_t now);
        void                  run() { t_(); }
        [[nodiscard]] bool    isPeriod() const { return isPeriod_; }

      private:
        types::Task t_;
        int64_t     expiration_;
        int64_t     interval_;
        bool        isPeriod_;
        int64_t     seqNo_;
    };

    struct TimerGreator
    {
        bool operator()(const Timer::s_ptr& lhs, const Timer::s_ptr& rhs) const
        {
            return lhs->getExpir() > rhs->getExpir();
        }
    };
}  // namespace foundation
}  // namespace xncc